<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class MY_Form_Validation extends CI_Form_validation {
    
    public $_error_prefix = '<p class="error">';
     
    public function __construct()
    {
        parent::__construct();
        $this->ci =& get_instance();
        $this->ci->load->database();
    }
    
    // ------------------------------------------------------------------------
    
    public function unique($value, $params)
    {
        $this->set_message('unique', 'The %s is already being used.');
        
        list($table, $field) = explode('.', $params, 2);
        
        $query = $this->ci->db->select($field)
                              ->where($field, $value)
                              ->where('deleted', 'n')
                              ->get($table, 1);
                          
        return $query->row_array() ? FALSE : TRUE;
    }
    
    // ------------------------------------------------------------------------
    
    public function alpha_space($str)
    {
        $this->set_message('alpha_space', 'The %s field contains invalid characters.');
        return ( ! preg_match("/^([a-z ])+$/i", $str)) ? FALSE : TRUE;
    }
    
    // ------------------------------------------------------------------------
    
    public function exists($value, $params)
    {
        $this->set_message('exists', 'The %s field value does not exist.');
        
        list($table, $field) = explode('.', $params, 2);
        
        if (is_array($value))
		{
			$query = $this->CI->db->select($field)
								  ->where_in($field, $value)
								  ->where('deleted', 'n')
								  ->get($table, 1);
		}
		else
		{
			$query = $this->CI->db->select($field)
								  ->where($field, $value)
								  ->where('deleted', 'n')
								  ->get($table, 1);
		}
                          
        return (bool) $query->row_array();
    }
    
    // ------------------------------------------------------------------------
    
}

/* End of file my_form_validation.php */
/* Location: ./application/libraries/my_form_validation.php */